package com.jlt.tag;

import java.io.IOException;

import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;

import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

public class BaseTag extends TagSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	protected String attributeName;

	public BaseTag() {
		super();
	}

	/**
	 * 
	 */
	protected Object getManagerBean(String managerName) {
		WebApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(pageContext
				.getServletContext());
		return context.getBean(managerName);
	}

	/**
	 * @param paramValue
	 */
	protected void writeValue2Jsp(Object paramValue) {
		JspWriter out = pageContext.getOut();
		try {
			out.print(paramValue);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	protected void saveValues2PageContext(Object paramMap) {
		pageContext.setAttribute(attributeName, paramMap);
	}

	public void setAttributeName(String attributeName) {
		this.attributeName = attributeName;
	}

	public String getAttributeName() {
		return attributeName;
	}

}